package com.hibase.core.interfacetask.controller;


import com.github.pagehelper.PageInfo;
import com.hibase.common.entity.ResponseModel;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.interfacetask.constant.InterfaceTypeConstant;
import com.hibase.core.interfacetask.entity.MdsInterfaceType;
import com.hibase.core.interfacetask.entity.vo.*;
import com.hibase.core.interfacetask.service.MdsInterfaceTypeService;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;
import com.hibase.core.web.entity.OperationIdsEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 接口业务类型表 前端控制器
 * </p>
 *
 * @author zhou_jw
 * @since 2020-08-21
 */
@RestController
@RequestMapping("/mds-interface-type")
@Api(tags = "接口业务类型表")
public class MdsInterfaceTypeController {

    @Autowired
    private MdsInterfaceTypeService mdsInterfaceTypeService;

    @ApiOperation(value = "查询接口业务类型表列表", httpMethod = "POST" , response = MdsInterfaceTypeListVO.class)
    @HibasePostRequestMapping(value = "selectMdsInterfaceTypeList")
    public ResponseModel<MdsInterfaceTypeListVO> selectMdsInterfaceTypeList(@RequestBody MdsInterfaceTypeSearchVO searchVO) {

        PageInfo result = mdsInterfaceTypeService.selectMdsInterfaceTypeList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), MdsInterfaceTypeListVO.class));

        return ResponseModel.successMsg(result);
    }

    @ApiOperation(value = "新增接口业务类型表记录", httpMethod = "POST" , response = OperationIdEntity.class)
    @HibasePostRequestMapping(value = "insertMdsInterfaceType")
    public ResponseModel<String> insertMdsInterfaceType(@RequestBody MdsInterfaceTypeInsertVO insertVO) {

        MdsInterfaceType entity = EntityUtil.transform(insertVO, MdsInterfaceType.class);

        mdsInterfaceTypeService.saveMdsInterfaceType(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "修改接口业务类型表记录", httpMethod = "POST" , response = OperationIdEntity.class)
    @HibasePostRequestMapping(value = "updateMdsInterfaceType")
    public ResponseModel<String> updateMdsInterfaceType(@RequestBody MdsInterfaceTypeUpdateVO updateVO) {

        MdsInterfaceType entity = EntityUtil.transform(updateVO, MdsInterfaceType.class);

        mdsInterfaceTypeService.saveMdsInterfaceType(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "查询接口业务类型表详情", httpMethod = "POST" , response = MdsInterfaceTypeViewVO.class)
    @HibasePostRequestMapping(value = "viewMdsInterfaceTypeDetails")
    public ResponseModel<MdsInterfaceTypeViewVO> viewMdsInterfaceTypeDetails(@RequestBody OperationIdEntity operationidEntity) {

        return ResponseModel.successMsg(EntityUtil.transform(mdsInterfaceTypeService.viewMdsInterfaceType(operationidEntity.getId()), MdsInterfaceTypeViewVO.class));
    }

//    @ApiOperation(value = "删除接口业务类型表记录", httpMethod = "POST")
//    @HibasePostRequestMapping(value = "/deleteMdsInterfaceType")
//    public ResponseModel<String> deleteMdsInterfaceType(@RequestBody OperationIdEntity delete) {
//
//        mdsInterfaceTypeService.deleteMdsInterfaceType(delete.getId());
//
//        return super.successMsg();
//    }
    @ApiOperation(value = "启用事件", httpMethod = "POST" , response = MdsInterfaceTypeListVO.class)
    @HibasePostRequestMapping(value = "/enableEvents")
    public ResponseModel<MdsInterfaceTypeListVO> enableEvents(@RequestBody OperationIdsEntity eventsIdsVo) {

        mdsInterfaceTypeService.changeEventsStatus(eventsIdsVo.getIds(), InterfaceTypeConstant.RECORD_STATUS_ENABLE);
        //此处需要返回对象信息
        MdsInterfaceTypeSearchVO searchVO=new MdsInterfaceTypeSearchVO();
        PageInfo result = mdsInterfaceTypeService.selectMdsInterfaceTypeList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), MdsInterfaceTypeListVO.class));

        return ResponseModel.successMsg(result);
        //return super.successMsg();
    }

    @ApiOperation(value = "停用事件", httpMethod = "POST" , response = MdsInterfaceTypeListVO.class)
    @HibasePostRequestMapping(value = "/disabledEvents")
    public ResponseModel<String> disabledEvents(@RequestBody OperationIdsEntity eventsIdsVo) {

        mdsInterfaceTypeService.changeEventsStatus(eventsIdsVo.getIds(), InterfaceTypeConstant.RECORD_STATUS_DISABLED);
        //此处需要返回对象信息
        MdsInterfaceTypeSearchVO searchVO=new MdsInterfaceTypeSearchVO();
        PageInfo result = mdsInterfaceTypeService.selectMdsInterfaceTypeList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), MdsInterfaceTypeListVO.class));

        return ResponseModel.successMsg(result);
        //return super.successMsg();
    }


}
